﻿using MrPP.iot;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace MrPP.SerriedCabinet
{
    public class InitialStatusFactory : GDGeek.Singleton<InitialStatusFactory>, IEventFactory
    {

        public Action<Data> onRecevie
        {
            get;
            set;
        }
        [Serializable]
        public class Status
        {
            public int area;
            public long datetime;
            public int[] positions;
            public int[] status;
        }
        [Serializable] 
        public struct Data
        {
            public Status[] areas;
        }
        public string type => "initialStatus";
        static public System.DateTime Time(long datetime) {
            System.DateTime startTime = new System.DateTime(1970, 1, 1); 

            return startTime.AddTicks(datetime * 10000);
        }
        public void post(string data)
        {
            Data evt = JsonUtility.FromJson<Data>(data);
            Debug.Log(JsonUtility.ToJson(evt));

            if (evt.areas.Length > 0) { 
                var time = Time(evt.areas[0].datetime);
            }
            onRecevie?.Invoke(evt);
        }

      
    }
}
